<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @author Anh Nguyen <duyanhnguyen@vccorp.vn>
 * @copyright 2012
 */

class Landing extends MX_Controller
{

    function __construct()
    {
        parent::__construct();
        $this->load->library('Admin_Layout');
		
    }
    
    public function index()
    {
        $this->mycommon->authAdmin();
        $data = array();
        $this->admin_layout->view('landing/landing_view');
    }
	
	public function edit($optionName='header')
    {
    	$this->load->library('Form_validation');
		$this->load->model('setting/setting_model');
        $this->mycommon->authAdmin();
		if ($optionName == '' && strlen($optionName)== 0) {
            show_404();
        }
        $valueOption = $this->setting_model->getOptionByName($optionName);

        $data = array();
		$data['error']='';
		$data['optionName'] = $optionName;
		$data['OptionValue'] = $valueOption['value'];
		if ($this->input->post('frmToken') && $this->session->userdata('frmToken') && $this->input->post('frmToken') == $this->session->userdata('frmToken')) {
           
            $array = array(
				'key'=>$optionName,
                'value'  =>  $this->input->post('content_vn'),
                
            );
            
            if ($this->setting_model->setOption($array['key'], $array['value'])) {
                redirect('admin/landing/edit/'.$optionName);
            } else {
                $data['error'] = 'Có lỗi xảy ra, vui lòng thử lại';
            }
            
        }
		
		$data['frmToken'] = uniqid();
        $this->session->set_userdata('frmToken', $data['frmToken']);
        $this->minifier->AddJsNoPack('uploadify/jquery.uploadify.min');
        $this->minifier->AddJsNoPack('ckeditor/ckeditor');
        $this->minifier->AddJsNoPack('ckeditor/adapters/jquery');
        $this->admin_layout->view('landing/landing_edit', $data);
    }

}

?>
